services:
  db:
    image: postgres:16.2-alpine3.19
    environment:
      - POSTGRES_DB=${POSTGRES_DB_NAME}
      - POSTGRES_USER=${POSTGRES_USER_NAME}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - PGUSER=${POSTGRES_USER_NAME}
      - PGDATABASE=${POSTGRES_DB_NAME}
    volumes:
      - storage_data:/var/lib/postgresql/data
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 5s
  
  db_admin:
    image: adminer:4.8.1
    restart: always
    ports:
      - ${DB_ADMIN_PORT}:8080

  app:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - DB_HOST=db
      - DB_PORT=5432
      - DB_PASSWORD=${POSTGRES_PASSWORD}
      - DB_USER=${POSTGRES_USER_NAME}
      - DEFAULT_ADMIN_TOKEN=${DEFAULT_ADMIN_TOKEN}
      - DEFAULT_USER_TOKEN=${DEFAULT_USER_TOKEN}
    depends_on: 
      db:
        condition: service_healthy
    restart: always
    ports:
      - ${APP_PORT}:8080
  
  app_cache:
    image: redis:7.2.4-alpine3.19
    restart: always

volumes:
  storage_data:
    name: ${DOCKER_VOLUME}
